// var timer = $('.time').children('span');
var timer = document.querySelector('.time span');

function md() {
    // 删除字符串中所有的-
    var reg = new RegExp("-", "g");
    // 获取当前时间
    var newTime = new Date();
    // 获取618购物节时间
    var goTime = new Date('2022-6-18');
    var time = newTime - goTime;
    //换算日、时、分、秒
    //Math.floor向下取整
    //换算天
    var day = Math.floor(time / 1000 / 60 / 60 / 24);
    // replace删除字符串
    day = String(day).replace(reg, "");
    //换算时
    var h = Math.floor(time / 1000 / 60 / 60 % 24);
    h = String(h).replace(reg, "");
    h = h > 9 ? h : '0' + h;
    //换算分
    var m = Math.floor(time / 1000 / 60 % 60);
    m = String(m).replace(reg, "")
    m = m > 9 ? m : '0' + m;
    //换算秒
    var s = Math.floor(time / 1000 % 60);
    s = String(s).replace(reg, "")
    s = s > 9 ? s : '0' + s;
    var mayDay = day + '天' + h + '时' + m + '分' + s + '秒';
    // console.log(day);
    // var dateStr = mayDay.replace(/\-/g, '');
    timer.innerHTML = mayDay;

}
md();
// 清除计时器
setInterval(md, 1000);